package cn.net.isir.dao;

import cn.net.isir.entity.TimeRange;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author liuxubo
 * @filename TotalFlowStatisticsDao.java
 * @package cn.net.isir.dao
 * @email lxb@isir.net.cn
 * @date 2019/03/08
 * @comment
 * @since 1.8
 */
@Repository
public class TotalFlowStatisticsDao {
    @Resource
    protected SqlSessionTemplate sqlSessionTemplate;
    @Resource
    protected MinipIndexDataDao minipIndexDataDao;

    /**
     * 查询当日总流水
     *
     * @param salesman 销售人员ID列表(key:销售人员ID，value:销售人员时间列表)
     * @return 总流水
     */
    public BigDecimal queryDayTotalFlow(Map<String, List<TimeRange>> salesman, String turnedShopIds) {
        BigDecimal totalFlow = BigDecimal.ZERO;
        for(Map.Entry<String,List<TimeRange>> saleman : salesman.entrySet()){
            Map map = minipIndexDataDao.queryDayFlow(saleman.getKey(), turnedShopIds, saleman.getValue());
            BigDecimal dayFlow = (BigDecimal) map.get("dayFlow");
            totalFlow = totalFlow.add(dayFlow);
        }
       /* salesman.forEach((key, value) -> {
            Map map = minipIndexDataDao.queryDayFlow(key, turnedShopIds, value);
            BigDecimal dayFlow = (BigDecimal) map.get("dayFlow");
            totalFlow = total.add(dayFlow);
        });*/
        return totalFlow;
    }

    /**
     * 查询当月总流水
     *
     * @param salesman 销售人员ID列表(key:销售人员ID，value:销售人员时间列表)
     * @return 总流水
     */
    public BigDecimal queryMonthTotalFlow(Map<String, List<TimeRange>> salesman, String turnedShopIds) {
        BigDecimal totalFlow = BigDecimal.ZERO;
        for (Map.Entry<String, List<TimeRange>> entry : salesman.entrySet()) {
            String key = entry.getKey();
            List<TimeRange> value = entry.getValue();
            BigDecimal dayFlow = minipIndexDataDao.queryMonthFlow(key, turnedShopIds, value);
            totalFlow = totalFlow.add(dayFlow);
        }
        return totalFlow;
    }
}
